// pages/shop/shopDetail.js
var app = getApp();
Page({
  data: {},
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady: function () {
    // 页面渲染完成
    getAddresses(this)
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onShareAppMessage: function (res) {
    return {
      title: '美甲美睫半永久化妆造型',
      path: '/pages/homepage/homepage?id=' + wx.getStorageSync("userid"),
    }
  },
  onUnload: function () {
    // 页面关闭
  }
  , deleteAdd: function (e) {
    var that = this;
    wx.request({
      url: app.globalData.allUrl + "/addressAction/deleteAddressByAddId",
      data: {
        addId: e.target.dataset.addid
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        // success
        that.setData({
          addresses: ""
        })
        if( wx.getStorageSync('addressID')==e.target.dataset.addid){//同时把本地的地址删除
          wx.setStorageSync('addressID', "")
        }     
        setTimeout(function () {
          getAddresses(that)
        }, 500)
      }
    })
  }
})


function getAddresses(that) {
  wx.request({
    url: app.globalData.allUrl + "/addressAction/getAddress",
    data: {
      userID: wx.getStorageSync('userid')
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
     // console.log(res.data)
      that.setData({
        addresses: res.data
      })
    }
  })
}